<template>
  <div class="form-hou">
      <Form  ref="form" :rules="rule" :model="form">
        <FormItem  prop="imgPath">
          <PictureEditItem :isLoad="true" :uploadList="uploadList" :maxlength="19" upLoadType="image" @uploadPic="uploadPic"></PictureEditItem>
        </FormItem>
      </Form>
      <!-- <Button type="primary" class="save" size="large" :disabled="disabled" @click="onSave">保存</Button> -->
  </div>
</template>
<script>
import PictureEditItem from "@/components/PictureEditItem"
import { mapGetters } from 'vuex'
export default {
  components: {
    PictureEditItem
  },
  data() {
    return {
      modal: false,
      disabled: false,
      storeContractId: null,
      form: {
        imgPath: []
      },
      order_id: '',
      uploadList: []
    }
  },
  methods: {
    getData(data) {
      this.uploadList = data.map(item => {
        return {
            url: item.url,
            imgUrl: item.url,
            status: "finished",
            name: item.name
          }
      })
      this.form.imgPath = data.map(item => {
        return {
          user_name: item.user_name,
          user_id: item.user_id,
          user_type: item.user_type,
          company_id: item.company_id,
          url: item.url,
          name: item.name,
        }
      })
    },
    updataForm(id) {
      this.$refs.form.resetFields()
      this.form = {
        rewardIntegral: '',
        rewardRemark: ''
      }
      
      this.disabled =  false
      this.company_id = id
      this.openModal()
    },
    openModal(item) {
      this.modal = true;
      this.order_id = item.order_id
      this.getData(item)
    },
    uploadPic(value) {
        this.form.imgPath = value.map(item => {
          return {
            user_name: this.userInfo.userName,
            user_id: this.userInfo.id,
            user_type: this.userInfo.user_type,
            company_id: this.userInfo.current_company_id,
            url: item.url,
            name: item.name,
          }
        })
    },
    closeModal() {
      this.modal = false
    },
    onSave() {
      for(let i = 0; i<this.form.imgPath.length; i++) {
        if (!this.form.imgPath[i]) delete this.form.imgPath[i]
      }
        let param = {
          order_id: this.order_id,
          file: this.form.imgPath
        }
          this.$jsonPost(`/order/addMyUpload`, param).then(data => {
            this.closeModal()
            this.$Notice.success({
              title: '操作成功'
            })
            this.$emit("complete")
          }).catch(() => {
            this.closeModal()
          })
    }
  },
  computed: {
    ...mapGetters([
    'userInfo'
    ]),
  }
}
</script>
